package com.briup.ch10;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/11
 * @Description:
 */
public class Test04 {
    public static void main(String[] args) {
        new Thread("t1"){
            @Override
            public void run(){
                for (int i = 1; i < 30; i++) {
                    System.out.println(Thread.currentThread().getName()+" "+i);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();

        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 100; i>=50; i--) {
                    System.out.println(Thread.currentThread().getName()+" "+i);
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"t2");
        t2.setDaemon(true);//设置守护线程/精灵线程/后台线程
        //用于保障前台线程正常运行，JVM只关心前台线程，不管后台线程的所以不会执行完t2，前台线程结束就直接结束了
        t2.start();
        //一直等到t2执行完毕
        try {
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


    }
}
